//
//  TTSendButtonView.m
//  TaoTuo
//
//  Created by LG on 2020/8/10.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTSendButtonView.h"

@interface TTSendButtonView ()

@property (nonatomic, strong) UIButton *sendBtn;
@property (nonatomic, strong) UIButton *startValuationBtn;

@property (nonatomic, copy) dispatch_block_t sendBlock;
@property (nonatomic, copy) dispatch_block_t startValuationBlock;

@end

@implementation TTSendButtonView

+ (instancetype)createSendButtonViewAndClickSendButtonBlock:(dispatch_block_t)sendBlock startValuationBtnBlock:(dispatch_block_t)startValuationBlock
{
    TTSendButtonView *view = [[self alloc] init];
    view.sendBlock = sendBlock;
    view.startValuationBlock = startValuationBlock;
    return view;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        _sendBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_sendBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#EEEEEE)] forState:UIControlStateDisabled];
        [_sendBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#DDC7F7)] forState:UIControlStateNormal];
        [_sendBtn setTitle:@"直接寄送" forState:UIControlStateNormal];
        _sendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_sendBtn setTitleColor:UIColorHex(#AAAAAA) forState:UIControlStateDisabled];
        [_sendBtn setTitleColor:UIColorHex(#6A22BC) forState:UIControlStateNormal];
        [_sendBtn addTarget:self action:@selector(sendBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_sendBtn];
        _sendBtn.enabled = NO;
        [_sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.height.equalTo(self);
            make.width.mas_equalTo(90*kScale);
        }];
        
        
        _startValuationBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_startValuationBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#DEDEDE)] forState:UIControlStateDisabled];
        [_startValuationBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#9343EB)] forState:UIControlStateNormal];
        [_startValuationBtn setTitle:@"开始估价" forState:UIControlStateNormal];
        _startValuationBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [_startValuationBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateDisabled];
        [_startValuationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_startValuationBtn addTarget:self action:@selector(startValuationBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_startValuationBtn];
        _startValuationBtn.enabled = NO;
        [_startValuationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.height.equalTo(self);
            make.left.equalTo(self.sendBtn.mas_right);
        }];
        
        

        self.layer.cornerRadius = 20;
        self.layer.masksToBounds = YES;
        
        
        
    }
    return self;
}

- (void)setLeftBtnTitle:(NSString *)leftTitle rightBtnTitle:(NSString *)rightTitle
{
    [self.sendBtn setTitle:leftTitle forState:UIControlStateNormal];
    [self.startValuationBtn setTitle:rightTitle forState:UIControlStateNormal];
}


- (void)setButtonEnabled:(BOOL)enabled
{
    self.sendBtn.enabled = enabled;
    self.startValuationBtn.enabled = enabled;
}

/// 直接寄送
- (void)sendBtnClick
{
    if (self.sendBlock) {
        self.sendBlock();
    }
}

/// 开始估价
- (void)startValuationBtnClick
{
    if (self.startValuationBlock) {
        self.startValuationBlock();
    }
}



@end
